﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

public class XLoadMgr
{
    //加载完马上释放，仅仅适用于一些不需要持久暂时的资源。如：TextAsset
    public static void LoadAssetAsyncRelease<T>(string key, Action<T> callBack)
    {
        LoadAssetAsyncReleaseInternal(key, callBack);
    }

    private static async void LoadAssetAsyncReleaseInternal<T>(string key, Action<T> callBack)
    {
        var op = Addressables.LoadAssetAsync<T>(key);
        var asset = await op.Task;
        callBack.Invoke(asset);
        Addressables.Release(asset);
    }
}
